package com.wanhe.vip.module.info;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.wanhe.vip.R;
import com.wanhe.vip.api.bean.VipCoupon;
import com.wanhe.vip.module.base.BaseDialog;

/**
 * Created by XieZaiWei on 2017/4/24.
 */

public class DoConsumeDialog extends BaseDialog implements View.OnClickListener{
	private TextView tv_prePay;
	private TextView tv_cash;
	private TextView tv_couponType;
	private TextView tv_couponName;
	private EditText et_verifyCode;

	private String mCardNo;
	private String mBillAmount;
	private String mPrePay;
	private String mCash;
	private VipCoupon mVipCouponModel;
	private VipInfoPresenter mVipInfoPresenter;

	public DoConsumeDialog(Context context, String cardNo, String billAmount, String prePay, String cash, VipCoupon vipCouponModel, VipInfoPresenter vipInfoPresenter) {
		super(context);
		mCardNo = cardNo;
		mBillAmount = billAmount;
		mPrePay = prePay;
		mCash = cash;
		mVipCouponModel = vipCouponModel;
		mVipInfoPresenter = vipInfoPresenter;
	}


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.do_consume_dialog);
		tv_prePay = (TextView) findViewById(R.id.tv_prePay);
		tv_cash = (TextView) findViewById(R.id.tv_cash);
		tv_couponType = (TextView) findViewById(R.id.tv_couponType);
		tv_couponName = (TextView) findViewById(R.id.tv_couponName);
		et_verifyCode = (EditText) findViewById(R.id.et_verifyCode);

		findViewById(R.id.btn_ok).setOnClickListener(this);
		findViewById(R.id.btn_cancel).setOnClickListener(this);

		if (mPrePay == null || "".equals(mPrePay)) {
			tv_prePay.setText("0元");
		} else {
			tv_prePay.setText(mPrePay + "元");
		}

		if (mCash == null || "".equals(mCash)) {
			tv_cash.setText("0元");
		} else {
			tv_cash.setText(mCash + "元");
		}

		if (mVipCouponModel != null) {
			switch (mVipCouponModel.getCouponType()) {
				case "cashCoupon"://现金优惠券
					tv_couponType.setText("现金优惠券");
					break;

				case "discountCoupon"://折扣优惠券
					tv_couponType.setText("折扣优惠券");
					break;

				case "giftCoupon"://礼品券
					tv_couponType.setText("礼品券");
					break;

				default:
					break;
			}
			tv_couponName.setText(mVipCouponModel.getName());

		} else {
			tv_couponType.setText("无");
			tv_couponName.setText("无");
		}


	}

	@Override
	public void show() {
		super.show();
	}

	@Override
	public void dismiss() {
		super.dismiss();

	}

	@Override
	public void onClick(View view) {
		int id = view.getId();
		if(id == R.id.btn_ok){
			String verifyCode = et_verifyCode.getText().toString();
			mVipInfoPresenter.doConsume(mCardNo, mBillAmount, mPrePay, mCash, mVipCouponModel, verifyCode);
			dismiss();

		}else if(id == R.id.btn_cancel){
			dismiss();
		}
	}
}
